package com.zhao.modleclass.activity;

import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.zhao.modleclass.R;
import com.zhao.modleclass.adapter.BiaoQianAdapter;
import com.zhao.modleclass.adapter.SC_MoDenTeacherAdapter;
import com.zhao.modleclass.adapter.SC_TeacherRActivityAdapter;
import com.zhao.modleclass.bean.SearchClassBiaoQianBean;
import com.zhao.modleclass.presenter.SearchPresenter;
import com.zhao.modleclass.utils.SpacesItemDecoration;
import com.zhao.modleclass.view.ISearchCLassView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

public class SC_TeacherRActivity extends AppCompatActivity implements ISearchCLassView {
    private static final String TAG = "";
    @Bind(R.id.iv_activity_sc_teacher_Finsh)
    ImageView ivActivityScTeacherFinsh;
    @Bind(R.id.Recycler_activity_sc_teacher)
    RecyclerView RecyclerActivityScTeacher;
    @Bind(R.id.tv_activity_sc_teacher_Title)
    TextView tvActivityScTeacherTitle;
    @Bind(R.id.refresh_activity_sc_teacher_w)
    PullToRefreshScrollView refreshActivityScTeacher;
    private Context mContext = this;
    private SearchPresenter searchPresenter;
    private int tage = 0;
    private int page = 2;

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sc__teacher_r);
        //设置状态栏的颜色
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            //获取样式中的属性值
            TypedValue typedValue = new TypedValue();
            this.getTheme().resolveAttribute(Color.parseColor("#FF4081"), typedValue, true);
            int[] attribute = new int[]{Color.parseColor("#FF4081")};
            TypedArray array = this.obtainStyledAttributes(typedValue.resourceId, attribute);
            int color = array.getColor(0, Color.parseColor("#FF4081"));
            array.recycle();
            window.setStatusBarColor(color);
        }
        ButterKnife.bind(this);
        Intent intent = getIntent();
        final int tagID = intent.getIntExtra("tagRID", 373);
        String TitleName = intent.getStringExtra("TitleName");
        tvActivityScTeacherTitle.setText(TitleName);
        iniListener();
        final LinearLayoutManager manager = new LinearLayoutManager(mContext);
        RecyclerActivityScTeacher.addItemDecoration(new SpacesItemDecoration(3));
        RecyclerActivityScTeacher.setLayoutManager(manager);
        //https://mrobot.pclady.com.cn/modern/x/modern.pclady.com.cn/app/course/courseListWithTag.do?pageSize=10&tagId=373&pageNo=1
        searchPresenter = new SearchPresenter(this);
        final Map<String, String> map = new HashMap<>();
        map.put("pageSize", "10");
        map.put("tagId", tagID + "");
        map.put("pageNo", "1");
        searchPresenter.loginTeacherMoreActyvity(mContext, "courseListWithTag.do", map, RecyclerActivityScTeacher, manager, tage);
        refreshActivityScTeacher.setMode(PullToRefreshBase.Mode.BOTH);
        refreshActivityScTeacher.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                tage=0;
                map.put("pageSize", "10");
                map.put("tagId", tagID+"");
                map.put("pageNo", "1");
                searchPresenter.loginTeacherMoreActyvity(mContext, "courseListWithTag.do",map,RecyclerActivityScTeacher,manager,tage);
                refreshActivityScTeacher.onRefreshComplete();
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                tage=1;
                map.put("pageSize", "10");
                map.put("tagId", tagID+"");
                map.put("pageNo", page+"");
                searchPresenter.loginTeacherMoreActyvity(mContext, "courseListWithTag.do",map,RecyclerActivityScTeacher,manager,tage);
                page++;
                refreshActivityScTeacher.onRefreshComplete();
            }
        });

    }

    private void iniListener() {
        ivActivityScTeacherFinsh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    public void toSetAdapter(BiaoQianAdapter adapter) {

    }

    @Override
    public void showError(Exception e) {

    }

    @Override
    public void getTeacher(SearchClassBiaoQianBean searchClassBiaoQianBean) {

    }

    @Override
    public void getTatle(List<SearchClassBiaoQianBean.TagListBean> mList) {

    }

    @Override
    public void toSetItemAdapter(SC_MoDenTeacherAdapter tAdapter) {

    }

    @Override
    public void toSetRAdapter(SC_TeacherRActivityAdapter adapter) {
        RecyclerActivityScTeacher.setAdapter(adapter);
       // refreshActivityScTeacher.onRefreshComplete();
    }
}
